﻿using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Windows;
using WpfApp4BlogReader.Models;
using WpfApp4BlogReader.ViewModels;

namespace WpfApp4BlogReader;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    //protected override void OnStartup(StartupEventArgs e)
    //{
    //    base.OnStartup(e);
    //}

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        // create some dummy blogs
        var blogs = new ObservableCollection<Blog> {
            MakeBlog(),
        };

        var vm = new MainVM(blogs);
        var win = new MainWindow
        {
            DataContext = vm
        };
        win.Show();
    }

    private Blog MakeBlog()
    {
        var uri = new Uri("/Images/bart.png", UriKind.Relative);
        var streamInfo = GetResourceStream(uri);
        Blogger blogger = new Blogger
        {
            Name = "Bart Simpson",
            Email = "bart@springfield.com",
            Picture = streamInfo.Stream
        };
        BlogPost blogPost1 = new BlogPost
        {
            When = new DateTime(2000, 8, 12),
            Title = "Post 1",
            Text = "This is the first post of Bart",
            Comments = {
                new BlogComment {
                    Name = "Homer S.",
                    Text = "Why you little...",
                    When = new DateTime(2000, 8, 13)
                }
            }
        };
        BlogPost blogPost2 = new BlogPost
        {
            When = new DateTime(2002, 3, 22),
            Title = "Post 2",
            Text = "This is the the second post",
            Comments = {
                new BlogComment {
                    Name = "Lisa S.",
                    Text = "Come on bart!",
                    When = new DateTime(2002, 3, 24)
                },
                new BlogComment {
                    Name = "Maggie S.",
                    Text = "Whhhaaa!",
                    When = DateTime.Now
                }
            }
        };
        return new Blog
        {
            Blogger = blogger,
            BlogTitle = "Bart's adventures",
            Posts = { blogPost1, blogPost2, }
        };
    }
}

